package com.stm.bi.repository.report;

import com.stm.framework.core.util.StringUtil;
import org.springframework.stereotype.Repository;
import com.stm.framework.repository.BaseRepository;
import com.stm.bi.dto.vo.ReportSubjectVO;
import com.stm.bi.repository.report.mapper.ReportSubjectMapper;
import com.stm.bi.repository.report.dataobject.ReportSubjectDO;
import com.stm.bi.dto.query.ReportSubjectListQry;
import com.stm.bi.dto.query.ReportSubjectPageQry;
import com.stm.framework.model.CustomizePage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.stm.framework.core.tookit.BeanToolkit;
/**
* 报表模型科目-仓储
*
* @author zhouyuanpeng
* @date 2025-05-22
*/
@Repository
public class ReportSubjectRepository extends BaseRepository<ReportSubjectMapper, ReportSubjectDO, ReportSubjectVO> {


    /**
    * 报表模型科目分页查询
    * @param reportSubjectPageQry 报表模型科目查询入参对象
    * @return
    */
   public CustomizePage<ReportSubjectVO> selectPage(ReportSubjectPageQry reportSubjectPageQry){
	LambdaQueryWrapper<ReportSubjectDO> queryWrapper = buildeQueryWrapper(reportSubjectPageQry);
        IPage<ReportSubjectDO> page = new Page(reportSubjectPageQry.getPageNum(),reportSubjectPageQry.getPageSize());
        page = this.baseMapper.selectPage(page, queryWrapper);
        CustomizePage<ReportSubjectVO> customizePage = new CustomizePage(BeanToolkit.instance().copyList(page.getRecords(), ReportSubjectVO.class), page.getSize(), page.getCurrent(), page.getTotal());
        return customizePage;
   }
    /**
    * 报表模型科目列表查询
    * @param reportSubjectListQry 报表模型科目查询入参对象
    * @return
    */
   public List<ReportSubjectVO> selectList(ReportSubjectListQry reportSubjectListQry){
	LambdaQueryWrapper<ReportSubjectDO> queryWrapper = buildeQueryWrapper(reportSubjectListQry);
        List<ReportSubjectDO> records = this.baseMapper.selectList(queryWrapper);
        return BeanToolkit.instance().copyList(records, ReportSubjectVO.class);
   }
   private LambdaQueryWrapper buildeQueryWrapper(ReportSubjectListQry reportSubjectListQry){
	LambdaQueryWrapper<ReportSubjectDO> queryWrapper = Wrappers.<ReportSubjectDO>lambdaQuery()
                .eq(StringUtil.isNotEmpty(reportSubjectListQry.getModelId()),ReportSubjectDO::getModelId,reportSubjectListQry.getModelId())
                .eq(StringUtil.isNotEmpty(reportSubjectListQry.getStandardId()),ReportSubjectDO::getStandardId,reportSubjectListQry.getStandardId())
                .eq(StringUtil.isNotEmpty(reportSubjectListQry.getSubjectId()),ReportSubjectDO::getSubjectId,reportSubjectListQry.getSubjectId())
                .eq(StringUtil.isNotEmpty(reportSubjectListQry.getSubjectName()),ReportSubjectDO::getSubjectName,reportSubjectListQry.getSubjectName())
                .eq(StringUtil.isNotEmpty(reportSubjectListQry.getFieldName()),ReportSubjectDO::getFieldName,reportSubjectListQry.getFieldName())
                .orderByAsc(ReportSubjectDO::getIdx);
        return queryWrapper;
   }
}
